<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">

			<u-form-item label="采购单别" v-if="judgeShow('tm001')">
				<u-input v-model="dataForm.tm001" placeholder="请输入采购单别" :disabled="judgeWrite('tm002')"></u-input>
			</u-form-item>
			<u-form-item label="采购单号" v-if="judgeShow('tm002')">
				<u-input v-model="dataForm.tm002" placeholder="请输入采购单号" :disabled="judgeWrite('tm002')"></u-input>
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('tm004')">
				<u-input v-model="dataForm.tm004" placeholder="请输入单据日期" :disabled="judgeWrite('tm004')"></u-input>
			</u-form-item>
			<u-form-item label="供应商" v-if="judgeShow('tm005')">
				<u-tag :text="buyName" type="success" />
			</u-form-item>
			<u-form-item label="采购人员" v-if="judgeShow('tm012')">
				<u-tag :text="buyNameTwo" type="success" />
			</u-form-item>
			<u-form-item label="交易币种" v-if="judgeShow('tm006')">
				<u-input v-model="dataForm.tm006" placeholder="请输入交易币种" disabled></u-input>
			</u-form-item>
			<u-form-item label="汇率" v-if="judgeShow('tm007')">
				<u-input v-model="dataForm.tm007" placeholder="请输入汇率" disabled></u-input>
			</u-form-item>
			<u-form-item label="付款条件" v-if="judgeShow('tm009')">
				<u-tag :text="buyNameThree" type="success" />
			</u-form-item>
			<u-form-item label="税率" v-if="judgeShow('tm017')">
				<u-input v-model="dataForm.tm017" placeholder="请输入税率" :disabled="judgeWrite('tm017')"></u-input>
			</u-form-item>
			<u-form-item label="采购金额" v-if="judgeShow('tm018')">
				<u-input v-model="dataForm.tm018" placeholder="请输入采购金额" :disabled="judgeWrite('tm018')"></u-input>
			</u-form-item>
			<u-form-item label="税额" v-if="judgeShow('tm019')">
				<u-input v-model="dataForm.tm019" placeholder="请输入税额" :disabled="judgeWrite('tm019')"></u-input>
			</u-form-item>
			<u-form-item label="含税金额(RMB)">
				<u-input v-model="dataForm.udf62" placeholder="含税金额(RMB)" :disabled="judgeWrite('udf62')"></u-input>
			</u-form-item>
			<u-divider color="#fa3534">详细信息</u-divider>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.asttnList"
					:key="i">
					<u-form-item label="序号" prop="orderCode">
						{{i+1}}
					</u-form-item>
					<u-form-item label="品号" prop="orderCode" v-if="judgeShow('tn004')">
						<u-input v-model="item.tn004" placeholder="品号" disabled></u-input>
					</u-form-item>
					<u-form-item label="规格" prop="orderCode" v-if="judgeShow('tn005')">
						<u-input v-model="item.tn005" placeholder="规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="采购数量" prop="orderCode" v-if="judgeShow('tn006')">
						<u-input v-model="item.tn006" placeholder="材料规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="采购单价" prop="orderCode" v-if="judgeShow('tn008')">
						<u-input v-model="item.tn008" placeholder="采购单价" disabled></u-input>
					</u-form-item>
					<u-form-item label="采购金额" prop="orderCode" v-if="judgeShow('tn009')">
						<u-input v-model="item.tn009" placeholder="采购金额" disabled></u-input>
					</u-form-item>
					<u-form-item label="已交数量" prop="orderCode" v-if="judgeShow('tn011')">
						<u-input v-model="item.tn011" placeholder="已交数量" disabled></u-input>
					</u-form-item>
					<u-form-item label="单位" prop="orderCode" v-if="judgeShow('tn007')">
						<u-input v-model="item.tn007" placeholder="单位" disabled></u-input>
					</u-form-item>
					<u-form-item label="预交货日" prop="orderCode" v-if="judgeShow('tn015')">
						<u-input v-model="item.tn015" placeholder="单位" disabled></u-input>
					</u-form-item>
					<u-form-item label="备注" prop="orderCode" v-if="judgeShow('tn010')">
						<u-input v-model="item.tn010" type="textarea" placeholder="备注"></u-input>
					</u-form-item>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getAsttm
	} from '@/api/workFlow/flowEngine'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		data() {
			return {
				buyName: '',
				buyNameTwo: '',
				buyNameThree: '',

				dataForm: {},
				asttnList: [],
				dictionaryInfo: {},
				id: '',
			}
		},
		methods: {
			init(data, id) {
				this.setting = data
				this.id = id
				this.getInfoFn(id)
			},
			getInfoFn(id) {
				getAsttm(id).then(res => {
					if (res.code == 200) {
						this.dataForm = res.data
						console.log('this.dataForm', this.dataForm);
						this.getDataInterfaceDataInfoMV002(this.dataForm.tm005)
						this.getDataInterfaceDataInfoMA003(this.dataForm.tm012)
						this.getDataInterfaceDataInfoMA004(this.dataForm.tm009)
					}
				})
			},
			/**
			 * 查询税种列表
			 */
			getDictionaryDataSelectorFn() {
				getDictionaryDataSelector('411695330707391429').then(res => {
					if (res.code == 200) {
						this.categoriesOfTaxesLst = res.data.list
						this.categoriesOfTaxesLst.forEach(res => {
							if (res.enCode == this.dataForm.tc018) {
								this.categoriesOfTaxesName = res.fullName
							}
						})
					}
				})
			},

			getDataInterfaceDataInfoMV002(id) {
				let data = {
					id,
					interfaceId: '435309912533253253',
					dblink: this.id,
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('435309912533253253', data).then(res => {
					if (res.code == 200) {
						this.buyName = res.data.JoinStr

					}
				})
			},
			getDataInterfaceDataInfoMA003(id) {
				let data = {
					id,
					interfaceId: '428345732257285957',
					dblink: this.id,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('428345732257285957', data).then(res => {
					if (res.code == 200) {
						this.buyNameTwo = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMA004(id) {
				let data = {
					id,
					interfaceId: '362115953258928709',
					dblink: this.id,
					propsValue: 'NA002',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362115953258928709', data).then(res => {
					if (res.code == 200) {
						this.buyNameThree = res.data.JoinStr
					}
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},


		}
	}
</script>